"""
添加客户页面
"""

from selenium.webdriver.common.by import By
from page.base_page import BasePage
from selenium.webdriver.support.select import Select

class AddClientPage(BasePage):
    url="/crm/index.php?m=customer&a=add"
    # 客户信息定位器
    owner_name_locator = (By.ID, "owner_name")
    clientname_locator = (By.ID, "name")
    client_job_locator = (By.ID, "industry")
    massge_origin_loctor = (By.ID, "origin")
    compan_hezi_locator = (By.ID, "ownership")
    compan_guoqi_locator = (By.ID, "ownership1")
    compan_mingying_locator = (By.ID, "ownership2")
    zip_code_loctor = (By.ID, "zip_code")
    year_monely_locator = (By.ID, "annual_revenue")
    pingfen_one_locator = (By.ID, "rating")
    pingfen_two_locator = (By.ID, "rating1")
    pingfen_three_locator = (By.ID, "rating2")
    address_provinces_locator = (By.XPATH, "//*[@id='form1']/table/tbody/tr[6]/td[2]/select[1]")
    address_city_locator = (By.XPATH, "//*[@id='form1']/table/tbody/tr[6]/td[2]/select[2]")
    address_district_locator = (
    By.CSS_SELECTOR, "#form1 > table > tbody > tr:nth-child(6) > td:nth-child(2) > select:nth-child(4)")
    stree_massge_locator = (By.XPATH, "//*[@id='form1']/table/tbody/tr[6]/td[2]/input")
    # 首要联系人定位器
    first_phone_name_locator = (By.XPATH, "//*[@id='form1']/table/tbody/tr[8]/td[2]/input")
    first_phone_chenghu_locator = (By.XPATH, "//*[@id='form1']/table/tbody/tr[8]/td[4]/input")
    first_phone_email_locator = (By.XPATH, "//*[@id='form1']/table/tbody/tr[9]/td[2]/input")
    first_phone_job_locator = (By.XPATH, "//*[@id='form1']/table/tbody/tr[9]/td[4]/input")
    first_phone_qq_locator = (By.XPATH, "//*[@id='form1']/table/tbody/tr[10]/td[2]/input")
    first_phone_phonenumber_locator = (By.XPATH, "//*[@id='form1']/table/tbody/tr[10]/td[4]/input")
    first_phone_beizhu_locator = (By.XPATH, "//*[@id='form1']/table/tbody/tr[11]/td[2]/textarea")
    # 附加信息定位
    addmassge_members_locator = (By.ID, "no_of_employees")
    addmassge_beizhu_locator = (By.ID, "description")
    save_locator = (By.CSS_SELECTOR, "#form1 > table > tfoot > tr > td > input:nth-child(1)")
    #提示添加成功定位器
    prompt_locator=(By.XPATH,"/html/body/div[5]/div[2]/div[1]/div/button")


    #操作
    #清理默认负责人
    def clear_ower_name(self):
        self.driver.find_element(*self.owner_name_locator).clear()
    # 输入负责人
    def input_owner_name(self,ower_name):
        self.driver.find_element(*self.owner_name_locator).send_keys(ower_name)
    # 输入客户名称
    def input_clientname(self,clientname):
        self.driver.find_element(*self.clientname_locator).send_keys(clientname)
    # 输入客户行业
    def input_client_job(self,client_job_value):
        a = self.driver.find_element(*self.client_job_locator)
        Select(a).select_by_value(client_job_value)
    # 客户信息来源
    def select_clientmassges_origin(self,massge_origin_value):
        b = self.driver.find_element(*self.massge_origin_loctor)
        Select(b).select_by_value(massge_origin_value)
    # 公司性质选择合资
    def select_compan_hezi(self):
        self.driver.find_element(*self.compan_hezi_locator).click()
    # 公司性质选择国企
    def select_compan_guoqi(self):
        self.driver.find_element(*self.compan_guoqi_locator).click()
    # 公司性质选择民营
    def select_compan_minying(self):
        self.driver.find_element(*self.compan_mingying_locator).click()
    # 填写邮编
    def input_zip_code(self,zip_code):
        self.driver.find_element(*self.zip_code_loctor).send_keys(zip_code)
    # 选择年营业额
    def select_year_money(self,year_money_value):
        c = self.driver.find_element(*self.year_monely_locator)
        Select(c).select_by_value(year_money_value)
    # 选择评分一星
    def select_pingfen_one(self):
        self.driver.find_element(*self.pingfen_one_locator).click()
    # 选择评分一星
    def select_pingfen_two(self):
        self.driver.find_element(*self.pingfen_two_locator).click()
     # 选择评分三星
    def select_pingfen_three(self):
        self.driver.find_element(*self.pingfen_three_locator).click()
    # 选择客户联系地址之选择省
    def select_provinces(self,address_provinces_vlue):
        provinces = self.driver.find_element(*self.address_provinces_locator)
        Select(provinces).select_by_value(address_provinces_vlue)
    #选择客户联系地址之选择市
    def select_city(self, address_city_vlue):
        city = self.driver.find_element(*self.address_city_locator)
        Select(city).select_by_value(address_city_vlue)
    # 选择客户联系地址之选择区
    def select_district(self,address_district_vlue):
        district = self.driver.find_element(*self.address_district_locator)
        Select(district).select_by_value(address_district_vlue)
     #填入街道
    def input_stree(self,stree_massge_vlue):
        self.driver.find_element(*self.stree_massge_locator).send_keys(stree_massge_vlue)
    # 屏幕滑到最底部
    def swipe_screen(self):
        js = "window.scrollTo(0,document.body.scrollHeight)"
        self.driver.execute_script(js)
    # 输入首要联系人信息
    def input_first_phone_name(self,first_phone_name):
        self.driver.find_element(*self.first_phone_name_locator).send_keys(first_phone_name)
    # 输入首要联系人称呼
    def input_first_phone_chenghu(self, first_phone_chenghu_value):
        self.driver.find_element(*self.first_phone_chenghu_locator).send_keys(first_phone_chenghu_value)
    # 输入首要联系人邮箱
    def input_first_phone_email(self, first_phone_email_value):
        self.driver.find_element(*self.first_phone_email_locator).send_keys(first_phone_email_value)
    # 输入首要联系人职位
    def input_first_phone_job(self, first_phone_job_value):
        self.driver.find_element(*self.first_phone_job_locator).send_keys(first_phone_job_value)
    # 输入首要联系人qq
    def input_first_phone_qq(self, first_phone_qq_value):
       self.driver.find_element(*self.first_phone_qq_locator).send_keys(first_phone_qq_value)
    # 输入首要联系人手机
    def input_first_phone_phonenumber(self, first_phone_phonenumber_value):
        self.driver.find_element(*self.first_phone_phonenumber_locator).send_keys(first_phone_phonenumber_value)
    # 输入首要联系人备注
    def input_first_phone_beizhu(self, first_phone_beizhu_value):
        self.driver.find_element(*self.first_phone_beizhu_locator).send_keys(first_phone_beizhu_value)
    # 选择员工数
    def select_addmassge_members(self,addmassge_members_value):
        members = self.driver.find_element(*self.addmassge_members_locator)
        Select(members).select_by_value(addmassge_members_value)
    # 输入附加信息备注
    def input_addmassge_beizhu(self,addmassge_beizhu_value):
         self.driver.find_element(*self.addmassge_beizhu_locator).send_keys(*addmassge_beizhu_value)
    # 点击保存
    def click_save_btn(self):
        self.driver.find_element(*self.save_locator).click()

    def warning_box(self):
        self.click_save_btn()
        alter_text=self.driver.switch_to.alert.text
        return alter_text








